const TransformPages = require('uni-read-pages');
const { webpack } = new TransformPages();

const GenerateAssetPlugin = require('generate-asset-webpack-plugin');
const createServerConfig = function() {
  const configJson = {
    ApiUrl: 'http://10.10.10.52:6080/capital_back/' // fu
    // ApiUrl: 'http://10.10.10.35:8081/',
    // ApiUrl: 'http://115.239.175.246:5902/capital_back/'
    // ApiUrl: 'http://115.239.175.246:5501/capital_back/'
    // ApiUrl: 'http://10.10.10.98:8081/capital_back/'
    // ApiUrl: 'http://10.10.10.32:8081/capital_back/'
    // ApiUrl: 'http://10.10.10.61:8081/capital_back'

  };

  const otherConfig = {
    dType: 'zdd',
    ddAppId: '5',
    zddAppId: '2',
    showConsole: true,
    name: '一码通',
    homeContent: '任务库,汇总分析,资金监管,项目分析,模板库,统计中心',
    homeContent可选值: '任务库,汇总分析,资金监管,项目分析,预警,模板库,统计中心'
  };

  const config = Object.assign(configJson, otherConfig);
  return JSON.stringify(config);
};

module.exports = {
  configureWebpack: {
    plugins: [
      new webpack.DefinePlugin({
        ROUTES: webpack.DefinePlugin.runtimeValue(() => {
          const tfPages = new TransformPages({
            includes: ['path', 'name', 'aliasPath']
          });
          return JSON.stringify(tfPages.routes);
        }, true)
      }),

      new GenerateAssetPlugin({
        filename: 'configMobile.json',
        fn: (compilation, cb) => {
          cb(null, createServerConfig());
        }
      })
    ]
  },
  transpileDependencies: ['uni-simple-router']
};
